﻿Imports System.Data.SqlClient
Public Class XoaKetQua

    Private _maSV As String
    Private _tenSV As String
    Dim TenSV As String

    Sub New(ByVal MaSV As String, ByVal TenSV As String)
        ' TODO: Complete member initialization 
        _maSV = MaSV
        _tenSV = TenSV
    End Sub

    Private Sub XoaKetQua_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT * FROM MonHoc  order by MonHoc_ID "
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Dim i As Integer
        For i = 0 To td.Rows.Count - 1 Step i + 1
            Me.cbxMonHoc.Items.Add(td.Rows(i)(1))
        Next
        Me.txtMaSV.Text = MaSV
        Me.txtTenSV.Text = TenSV
        con.Close()
    End Sub

    Private Sub btnSua_Click(sender As System.Object, e As System.EventArgs) Handles btnSua.Click
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        Dim TenMonHoc As String = cbxMonHoc.SelectedItem.ToString()
        cmd.CommandText = "select * from MonHoc where TenMonHoc='" + TenMonHoc + "'"
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Dim MaMonHoc As String = td.Rows(0)(0).ToString()
        cmd.CommandText = "DELETE KetQua WHERE ID_MonHoc='" + MaMonHoc + "' AND ID_SinhVien='" + MaSV + "'"
        Dim result As DialogResult
        result = MessageBox.Show("BẠN CÓ MUỐN XÓA THÔNG TIN KẾT QUẢ HỌC TẬP KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then
            cmd.ExecuteNonQuery()
            MessageBox.Show("XÓA THÀNH CÔNG", "THÔNG BÁO")
        End If
        con.Close()
        Close()
        Dim frm As New XoaKetQua(MaSV, TenSV)
        frm.Show()
    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub cbxMonHoc_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbxMonHoc.SelectedIndexChanged
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        Dim TenMonHoc As String
        TenMonHoc = cbxMonHoc.SelectedItem.ToString()
        cmd.CommandText = "select* from MonHoc where TenMonHoc='" + TenMonHoc + "'"
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Dim MaMonHoc As String = td.Rows(0)(0).ToString()
        cmd.CommandText = "SELECT LanThi,DiemThi,DiemTongKet FROM KetQua WHERE ID_MonHoc='" + MaMonHoc + "' AND ID_SinhVien='" + MaSV + "'"
        Dim rd1 As SqlDataReader
        rd1 = cmd.ExecuteReader()
        Dim td1 As DataTable = New DataTable()
        td1.Load(rd1)
        Me.txtLanThi.Text = td1.Rows(0)(0).ToString()
        Me.txtDiemThi.Text = td1.Rows(0)(1).ToString()
        Me.txtTongKet.Text = td1.Rows(0)(2).ToString()
        con.Close()
    End Sub

    Private Function MaSV() As String
        Throw New NotImplementedException
    End Function

End Class